﻿<%@ page contentType="text/html; charset=UTF-8" %>


<form id="kt_organ_add_form" name="kt_organ_add_form"  class="cmxform" method="POST">
<div class="ui-title re_ui-corner-top re_ui-helper-clearfix">机构管理->开通机构</div>
<div class="tableBox">
<div class="contentbox">

<div class="scroll" style="height:400px; overflow-y:auto">
<div id="organ_add_errmsg"></div>


<!-- 机构部分 -->
     
<fieldset>
	<legend>机构部分 </legend>
        <table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" class="jkt-tableStyle">
	<tr>
<td width="12%"  align="right" class="bluetd">机构简称：</td>
        <td width="22%"  align="left" class="bluetd2">
          <input id="dataorganizations_organ_abbreviation_add" name="dataorganizations_organ_abbreviation_add">          <span class="red-color">*</span>
        </td>
       
    <td align="right" class="bluetd">机构联系人：</td>
        <td   align="left" class="bluetd2">
          <input id="dataorganizations_organ_contact_add" name="dataorganizations_organ_contact_add">          <span class="red-color">*</span>
        </td>
<!-- ecorganization_citySel_add 用于回显下拉树选择的值 --> 
<!-- ecorganization_areaId_add  用于回显下拉树选择值的ID --> 
<!-- ataorganizations_add_dm 显示树的DIV --> 
<!-- showecorganizationMenu_add 函数用于显示树。 --> 
       
      <td  align="right" class="bluetd">机构所在地区：</td>
        <td  align="left" class="bluetd2">
            <input id="add_organ_info_citySel_add" name="add_organ_info_citySel_add" type="text" readonly />
            &nbsp;<a class="red-color" id="menuBtn_dadd" href="#" onclick="showadd_organ_infoMenu_add(); return false;">选择</a>
          <input type="hidden" id="add_organ_info_SysCustomId_add" name="add_organ_info_SysCustomId_add" value="" />
        </td>
    </tr>
	<tr>
	<td width="12%"   align="right" class="bluetd">机构全称：</td>
        <td   align="left" class="bluetd2">
          <input id="dataorganizations_organ_cpName_add" name="dataorganizations_organ_cpName_add"><span class="red-color">*</span>
        </td>
	
       
         <td  align="right" class="bluetd">机构电话：</td>
           <td   align="left" class="bluetd2" >
             <input id="dataorganizations_organ_mobileNo_add" name="dataorganizations_organ_mobileNo_add">
           </td>
         <td  align="right" class="bluetd">机构介绍：</td>
         <td  align="left" class="bluetd2">
           <input id="dataorganizations_organ_aboutInfo_add" name="dataorganizations_organ_aboutInfo_add">
         </td>
     </tr>
	<tr>
       <td class="bluetd" align="right">机构性质：</td>
        <td class="bluetd2" align="left">
          <select style="width:140px" id="dataorganizations_organ_cpNature_add" name="dataorganizations_organ_cpNature_add">
          <option value="">——请选择——</option>
          <option value="9">其它</option>
        </select>
        </td>
        
       <td   align="right" class="bluetd">机构地址：</td>
        <td   align="left" class="bluetd2">
          <input id="dataorganizations_organ_offAddress_add" name="dataorganizations_organ_offAddress_add">
        </td>
     <td   align="right" class="bluetd">机构法人：</td>
        <td   align="left" class="bluetd2">
          <input id="dataorganizations_organ_corporate_add" name="dataorganizations_organ_corporate_add">
        </td>
    </tr>
 
	  <tr><td class="bluetd1" align="right">角色分配:</td>
        <td class="bluetd1" colspan="5"  align="left">
        <span id="RoleArray"></span>
    </td>
  </tr> 
	
</table>
</fieldset>   

<!-- 操作员部分 -->
<fieldset>
	<legend>操作员部分 </legend>
    <table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" class="jkt-tableStyle">
    
	<tr>
        <td width="12%" align="right" class="bluetd">管理员账号：</td>
        <td width="22%" class="bluetd2">
          <input id="user_name_add" name="user_name_add"/>          <span class="red-color">*</span>        </td>
        <td width="12%" align="right" class="bluetd">管理员姓名：</td>
        <td width="22%" align="left" class="bluetd2">
          <input id="user_realname_add" name="user_realname_add"/>
       <td width="12%" align="right" class="bluetd">传真：</td>
        <td align="left" class="bluetd2">          <input id="user_fax_add" name="user_fax_add"/>        </td>
        </tr>
	    <tr>
        <td align="right" class="bluetd">登录密码：</td>
        <td align="left" class="bluetd2">
          <input id="user_password_add" name="user_password_add" type='password'/></td>
      
      
        <td align="right" class="bluetd">性别：</td>
        <td align="left" class="bluetd2">
          <select style="width:140px" id="user_sex_add" name="user_sex_add">
            <option value="男">男</option>
            <option value="女">女</option>
          </select>        </td>
        <td align="right" class="bluetd">工作电话：</td>
        <td align="left" class="bluetd2">          <input id="user_worktel_add" name="user_worktel_add"/>        </td>
     </tr>
	<tr>
	   <td align="right" class="bluetd">确认密码：</td>
        <td align="left" class="bluetd2">
          <input id="user_password_add2" name="user_password_add2" type='password'/></td>
        <td align="right" class="bluetd">手机号码：</td>
        <td align="left" class="bluetd2">          <input id="user_mobiletel1_add" name="user_mobiletel1_add"/>        </td>
        <td align="right" class="bluetd">电子邮件：</td>
        <td align="left" class="bluetd2">          <input id="user_email_add" name="user_email_add"/>        </td>
              
    </tr>
	 
     </table>
</fieldset>    
 
<div style="text-align:center">          
<input type="button" class="btns" id="organ_add_bt" value="开  通" style="margin-top:8px;" />&nbsp;&nbsp;
          <input type="reset" class="btns" value="重  置" style="margin-top:8px;" />&nbsp;&nbsp;
          </div>

</div>
</div>
</div>
<div id="ataorganizations_add_dm" style="display:none; position:absolute;height:212px; min-width:150px; background-color:white;border:1px solid;overflow-y:auto;overflow-x:auto;">
	<ul id="ataorganizations_dMenu_add" class="tree"></ul>
</div>
</form>
<script>



      var 	addorganInfo={};//本页变量
	    addorganInfo.addvalidate;
	    addorganInfo.upvalidate;
	    addorganInfo.ids='';
	    addorganInfo.addset;
	    addorganInfo.upset;
	    addorganInfo.addNodes=[];
	    addorganInfo.upNodes=[];
	    addorganInfo.addval=false;
	    addorganInfo.upval=false;
 
 
 
     

      $.ajax({
            type: "POST",
            url:"sys/SysArea/getAreaTree.do",
            dataType: "json",
            success:function(json){
                 addorganInfo.addNodes =strToObj(json.msg);                   
                 add_organ_infozreloadaddTree();
		        
            }
       })	
    addorganInfo.addset = {
		isSimpleData: true,
		treeNodeKey: "id",
		treeNodeParentKey: "pId",
		fontCss: setFont,
		expandSpeed : "",
		callback: {			
			click: add_organ_infoaddzTreeOnClick
		}
	}
  	 
  	 
  	function setFont(treeId, treeNode) {
		if (treeNode && treeNode.isParent) {
			return {color: "blue"};
		} else {
			return null;
		}
	}
  	 
  	 function add_organ_infoaddzTreeOnClick(event, treeId, treeNode) {
		if (treeNode) {
			var cityObj = $("#add_organ_info_citySel_add");
			cityObj.attr("value", treeNode.name);
			$("#add_organ_info_SysCustomId_add").val(treeNode.id);
			hideadd_organ_infoMenu_add();
		}
	}

	function add_organ_infozreloadaddTree() {	
		hideadd_organ_infoMenu_add();
		$("#ataorganizations_dMenu_add").zTree(addorganInfo.addset, addorganInfo.addNodes);
	}

	function showadd_organ_infoMenu_add() {	
	     $("#ataorganizations_add_dm").css({left:"129px", top: "31px"}).slideDown("fast");
	  }
	
	function hideadd_organ_infoMenu_add() {
		$("#ataorganizations_add_dm").fadeOut("fast");
	}
	
	
	   var organ_add_alidate;

    $(function() {
    
       $.ajax({
                type: "POST",
                url:"system/Role/getCheckbox.do",
                dataType: "json",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                success:function(json){
                    if(json.success){ 
                        $("#RoleArray").append(json.msg);
                    }else{
                        alertmsg(json.msg,"alert");
                    }
                }
           });
       
       
       
        organ_add_alidate = $("#kt_organ_add_form").validate({
            //errorLabelContainer: $("#organ_addform div.notification_false"),
            errorElement: "div",
            errorPlacement: function(error, element) {
			    $('#organ_add_errmsg').html("");
				error.appendTo( "#organ_add_errmsg" );
			},
			success: function(label) {
			    label.text("验证通过!").removeClass("error").addClass("success");
			},
            rules: {
                user_name_add:{
                    required: true,
                    stringMinLength : 4,
                    stringMaxLength : 15
                   
               },
               dataorganizations_organ_abbreviation_add:{
                    required: true,
                    stringMinLength : 4,
                    stringMaxLength : 15,
                    remote: {
                       url: "organiza/DataOrganizations/checkName.do",
                       type: "post",
                       contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                       data: {abbreviation: function() {
                           return $("#dataorganizations_organ_abbreviation_add").val()}
                       }
                   } 
               },
               
				dataorganizations_organ_contact_add : {
					required: true
			    },
				dataorganizations_organ_cpName_add : {
					required: true
			    }
			 
            },
            messages: {
                user_name_add:{
                    required: "管理员账号不能为空",
                    nozn:"管理员账号不能输入汉字",
                    stringMinLength : '管理员账号字符长度不能小于4个字符',
                    stringMaxLength : '管理员账号字符长度不能大于15个字符',
                    string:"管理员账号不能输入特殊字符"
                    
                }
                ,dataorganizations_organ_abbreviation_add:{
                    required: "机构简称不能为空",
                    nozn:"机构简称不能输入汉字",
                    stringMinLength : '机构简称字符长度不能小于4个字符',
                    stringMaxLength : '机构简称字符长度不能大于15个字符',
                    string:"机构简称不能输入特殊字符",
                    remote: "机构简称已存在"
                    
                }
                , 
				dataorganizations_organ_contact_add : {
				  required: "机构联系人不能为空"
				},    
				dataorganizations_organ_cpName_add : {
				  required: "管理员全称不能为空"
				}
				 
            },
            //onfocusout:false,
            onkeyup:false,
	        onsubmit:false
        })


        $('#organ_add_bt').click(function(){ 
            if(rulesByValidator(organ_add_alidate)){
           
                organ_add_submit();
            }
        }) 
  	   
        

    })
    
    function GetCheckBox() {
            var str="";
            jQuery("input[name='roleCheckbox']:checked").each(function(){
                str += (str==""?"":",") + $(this).val();
            })
            return str;
     }
      
     function  organ_add_submit(){
        //var checkbox_value = GetCheckBox();
        
        var checkbox_value = "1";
        var addOrganizationsJson="{'user':{'name':'"+$('#user_name_add').val()+"','password':'"+$('#user_password_add').val()+"','realname':'"+$('#user_realname_add').val()+"','sex':'"+$('#user_sex_add').val()+"','company':'"+$('#user_company_add').val()+"','worktel':'"+$('#user_worktel_add').val()+"','mobiletel1':'"+$('#user_mobiletel1_add').val()+"','mobiletel2':'','fax':'"+$('#user_fax_add').val()+"','email':'"+$('#user_email_add').val()+"','address':'','postalcode':'','idcard':'','blocked':'1','roleId':'"+$('#user_roleId_add').val()+"'},'cpName':'"+$('#dataorganizations_organ_cpName_add').val()+"','aboutInfo':'"+$('#dataorganizations_organ_aboutInfo_add').val()+"','areaId':'"+$('#add_organ_info_SysCustomId_add').val()+"','modeValue':'1','coopType':'1','corporate':'"+$('#dataorganizations_organ_corporate_add').val()+"','regAddress':'','offAddress':'"+$('#dataorganizations_organ_offAddress_add').val()+"','contact':'"+$('#dataorganizations_organ_contact_add').val()+"','mobileNo':'"+$('#dataorganizations_organ_mobileNo_add').val()+"','cpNature':'"+$('#dataorganizations_organ_cpNature_add').val()+"','phoneValue':'','abbreviation':'"+$('#dataorganizations_organ_abbreviation_add').val()+"','userRole':{'roleIdStr':'"+checkbox_value+"'}}";  
        //var userJson="{'id':'','name':'"+$('#user_name_add').val()+"','password':'"+$('#user_password_add').val()+"','realname':'"+$('#user_realname_add').val()+"','sex':'"+$('#user_sex_add').val()+"','company':'"+$('#user_company_add').val()+"','worktel':'"+$('#user_worktel_add').val()+"','mobiletel1':'"+$('#user_mobiletel1_add').val()+"','mobiletel2':'"+$('#user_mobiletel2_add').val()+"','fax':'"+$('#user_fax_add').val()+"','birthdayString':'"+$('#user_birthday_add').val()+"','email':'"+$('#user_email_add').val()+"','address':'"+$('#user_address_add').val()+"','postalcode':'"+$('#user_postalcode_add').val()+"','idcard':'"+$('#user_idcard_add').val()+"','blocked':'1','roleId':'"+$('#user_roleId_add').val()+"'}";  
        
            $.ajax({
                type: "POST",
                url:"organiza/DataOrganizations/dredge.do",
                data:{
                    dataorganizationsJson : addOrganizationsJson
                },
                dataType: "json",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                success:function(json){
                    if(json.success){
                        $("#organ_grid").trigger("reloadGrid");
                        alertmsg(json.msg,"info");
                    }else{
                        alertmsg(json.msg,"alert");
                    }
                }
           });
        }
  	     
         

</script>